//
//  NSDate+Commons.m
//  Categorys
//
//  Created by taihankeji on 2017/5/17.
//  Copyright © 2017年 taihankeji. All rights reserved.
//

#import "NSDate+Commons.h"

@implementation NSDate (Commons)

+ (NSString *)ymdStringWithType:(DateStringType)type timeInterval:(NSTimeInterval)timeInterval {
    NSDate *dateTime = [[self alloc] initWithTimeIntervalSince1970:timeInterval];
    return [dateTime getDateYMDHFStringWithType:type];
}


+ (NSString *)ymdhfStringWithType:(DateStringType)type timeInterval:(NSTimeInterval)timeInterval {
    NSDate *dateTime = [[self alloc] initWithTimeIntervalSince1970:timeInterval];
    return [dateTime getDateYMDHFStringWithType:type];
    
}


- (NSString *)getDateYMDStringWithType:(DateStringType)type {
    NSDateFormatter *formatter;
    if (!type) {
        
        formatter = [self formatterSetDateFormat:@"yyyy-MM-dd"];
        
    }else if (type == DateStringTypeDefualt) {
        
        formatter =  [self formatterSetDateFormat:@"yyyy-MM-dd"];
        
    }else if (type == DateStringTypeSprit) {
        
        formatter =  [self formatterSetDateFormat:@"yyyy/MM/dd"];
        
    }else if (type == DateStringTypePeriod) {
        
        formatter = [self formatterSetDateFormat:@"yyyy.MM.dd"];
        
    }
    
    NSString *dateString = [formatter stringFromDate:self];
    return dateString;
    
}

- (NSString *)getDateYMDHFStringWithType:(DateStringType)type {
    NSDateFormatter *formatter;
    if (!type) {
        
        formatter = [self formatterSetDateFormat:@"yyyy-MM-dd HH:mm"]; //大写的HH为24 小时制 小写的hh为12小时制
        
    }else if (type == DateStringTypeDefualt) {
        
        formatter =  [self formatterSetDateFormat:@"yyyy-MM-dd HH:mm"];
        
    }else if (type == DateStringTypeSprit) {
        
        formatter =  [self formatterSetDateFormat:@"yyyy/MM/dd HH:mm"];
        
    }else if (type == DateStringTypePeriod) {
        
        formatter =   [self formatterSetDateFormat:@"yyyy.MM.dd HH:mm"];
        
    }
    NSString *dateString = [formatter stringFromDate:self];
    return dateString;
}

- (NSDateFormatter *)formatterSetDateFormat:(NSString *)dateFormat{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    NSLocale *formatterLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"en_us"];
    [formatter setLocale:formatterLocal];
    [formatter setDateFormat:dateFormat];
    return formatter;
}



@end
